﻿using System.Data.SqlClient;
namespace BookManage
{
    internal class Dao
    {
       SqlConnection conn;
        public SqlConnection connect()
        {
            string sql = @"Data Source=LAPTOP-KCI0PGCG;Initial Catalog=BookDB;Integrated Security=True";
            conn = new SqlConnection(sql);//创建数据库连接对象
            conn.Open();
            return conn;
        }
        public SqlCommand command(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql,connect());
            return cmd;
        }
        public int Execute(string sql)//更新操作
        {
            return command(sql).ExecuteNonQuery();
        }
        public SqlDataReader read(string sql)//读取操作
        {
            return command(sql).ExecuteReader();
        }
        public void DaoClose()
        {
            conn.Close();
        }
    }
}
